'''
    1.项目的登录和注册模块的接口方法的封装
'''
# 1.导包

# 2.创建登录和注册模块封装的类
import app


class RegLoginApi:

    def __init__(self, session):
        self.session = session
        # 图片验证码URL
        self.url_img_verify_code = app.BASE_HOST + "/common/public/verifycode1/{}"
        # 短信验证码URL
        self.url_phone_verify_code = app.BASE_HOST + "/member/public/sendSms"
        # 注册URL
        self.url_reg = app.BASE_HOST + "/member/public/reg"
        # 登录URL
        self.url_login = app.BASE_HOST + "/member/public/login"
        # 查询登录状态URL
        self.url_is_login = app.BASE_HOST + "/member/public/islogin"

    # 获取图片验证码接口
    def get_img_verify_code(self, r="0.1426580900762553"):
        return self.session.get(url=self.url_img_verify_code.format(r))

    # 获取短信验证码接口
    def get_phone_verify_code(self, phone="18800011121", imgVerifyCode="8888", type="reg"):
        # 定义一个字典变量，用来接收请求数据
        data_form = {"phone": phone, "imgVerifyCode": imgVerifyCode, "type": type}
        return self.session.post(url=self.url_phone_verify_code, data=data_form)

    # 注册接口
    def user_register(self, phone="18800011121", password="123qqq", verifycode="8888", phone_code="666666",
                      dy_server="on", invite_phone=None):
        # 定义一个字典变量，用来接收请求数据
        data_form = {"phone": phone, "password": password, "verifycode": verifycode, "phone_code": phone_code,
                     "dy_server": dy_server, "invite_phone": invite_phone}
        return self.session.post(url=self.url_reg, data=data_form)

    # 登录接口
    def user_login(self, keywords="18800011121", password="123qqq"):
        # 定义一个字典变量，用来接收请求数据
        data_form = {"keywords": keywords, "password": password}
        return self.session.post(url=self.url_login, data=data_form)

    # 查询登录状态接口
    def query_user_login_status(self):
        return self.session.post(url=self.url_is_login)
